/**
 * Created by mac on 2017/7/4.
 */


export default  class Api {


    static Get(url,param,success,fail) {

        if (param){

            var keys = Object.keys(param);

            var totalParamString = '';

            keys.forEach((key,i)=> {

                var string;
                if (i === 0) {
                    string = '?';
                }
                else if (i > 0) {

                    string = '&';
                }

                var value = param[key];

                totalParamString += string;

                totalParamString = totalParamString + key + '=' + value;

            })

            url = url + totalParamString;
        }

        console.log('url='+url);


        fetch(url,
            {
                headers:
                    {
                        'appkey': 'ef1fc57c13007e33',
                        'Os':'android',
                        'Appversion':'2.1.3'
                    }
            })
            .then(res=>res.json())
            .then(resData=>{
                if(success){
                    success(resData);
                }
            }).catch(error=>{
            if(fail){
                fail(error);
            }
        })
    }
}